//
//  YMRightContentView.swift
//  AllClassDemo
//
//  Created by zeng on 2018/2/27.
//  Copyright © 2018年 youmy. All rights reserved.
//

import UIKit
//private let kBgColor : (CGFloat, CGFloat, CGFloat) = (230, 230, 230)//0xe6e6e6
private let kBgColor : (CGFloat, CGFloat, CGFloat) = (255, 255, 255)//0xe6e6e6

class YMRightContentView: UIView {

    fileprivate var titles:[String]?
    
    fileprivate let cellId = "cellId"
    
    lazy var collectionView:UICollectionView = {
        let kItemMargin:CGFloat = 1
        let kItemW:CGFloat = (self.frame.width - 4 * kItemMargin) / 3
        let kItemH:CGFloat = 112
        
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        layout.itemSize = CGSize(width: kItemW, height: kItemH)
        layout.minimumLineSpacing = kItemMargin
        layout.minimumInteritemSpacing = kItemMargin
        layout.sectionInset = UIEdgeInsetsMake(0, kItemMargin, 0, kItemMargin)
        
        let v = UICollectionView(frame: self.bounds, collectionViewLayout: layout)
        v.contentInset = UIEdgeInsetsMake(kItemMargin, 0, kItemMargin, 0)
        v.backgroundColor = UIColor(r: kBgColor.0, g: kBgColor.1, b: kBgColor.2)
        v.register(UINib.init(nibName: "YMCategoryCell", bundle: nil), forCellWithReuseIdentifier: cellId)
        v.showsHorizontalScrollIndicator = false
        v.dataSource = self
        v.delegate = self
        return v
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(collectionView)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}


// MARK: - UICollectionViewDataSource, UICollectionViewDelegate
extension YMRightContentView: UICollectionViewDataSource, UICollectionViewDelegate {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 20
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! YMCategoryCell
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        print("点击item:\(indexPath.item)")
    }
    
}


// MARK: - 刷新数据
extension YMRightContentView {
    func updata(_ brand: String) {
        print("刷新-" + brand + "-手机型号")
    }
}
